import * as types from '../actionTypes/counter';

// 处理数据的 reducer
export const counter = (state = 0, action) => {
  console.log('counter', state, action);
  switch (action.type) {
    case types.INCREMENT:
      return state + action.payload;

    case types.DECREMENT:
      return state - action.payload;

    case types.RANDOM:
      return Math.floor(Math.random() * 100); // 0~99 随机数

    default:
      return state;
  }
};
